package com.letfox.test.example;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.map.HashedMap;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import com.letfox.statistical.dao.DeviceStatisticDao;
import com.letfox.statistical.dao.GeoStatisticDao;
import com.letfox.statistical.enums.UDMDelEnums;
import com.letfox.statistical.model.UDMDeviceStatistic;
import com.letfox.statistical.model.UDMGeoStatistic;
import com.letfox.test.util.DateUtil;
import com.letfox.test.util.MyBatisUtil;
import com.letfox.user.dao.UserDao;
import com.letfox.user.enums.UserEnums;
import com.letfox.user.model.UUser;

 
/**
 * 单元测试
 */
public class GeoStatisticExample {

	/**
	 * 需要单元测试的时候在取消注释
	 */
	private GeoStatisticDao geoStatisticDao;
	@Test
	public void add_GeoStatistic(){
		
		try {
			SqlSession session = MyBatisUtil.getSqlSession(true);
			UDMGeoStatistic geoStatistic = new UDMGeoStatistic();
			geoStatistic.setUdmAdReoId("0011");
			geoStatistic.setAdPlanId("0011");
			geoStatistic.setGeoName("海南");
			geoStatistic.setPlayTime(new Date());
			geoStatistic.setShowTimes(1);
			geoStatistic.setClickTimes(1);
			geoStatistic.setDownloadTimes(1);
			geoStatistic.setAmount(new BigDecimal("22222.54"));
			geoStatistic.setCreateTime(new Date());
			geoStatistic.setUpdateTime(new Date());
			geoStatistic.setCreateBy("admin");
			geoStatistic.setUpdateBy("user");
			geoStatistic.setDel(UDMDelEnums.UDMDel.EFFECTIVE.getValue());
			
			geoStatisticDao = session.getMapper(GeoStatisticDao.class);
			geoStatisticDao.insert(geoStatistic);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	@Test
	public void DeviceStatistic_update_Test(){
		
		try {
			SqlSession session = MyBatisUtil.getSqlSession(true);

			UDMGeoStatistic geoStatistic = new UDMGeoStatistic();
			geoStatistic.setUdmAdReoId("0011");
			geoStatistic.setAdPlanId("0011");
			geoStatistic.setGeoName("HK");
			geoStatistic.setPlayTime(new Date());
			geoStatistic.setShowTimes(1);
			geoStatistic.setClickTimes(1);
			geoStatistic.setDownloadTimes(1);
			geoStatistic.setAmount(new BigDecimal("22222.54"));
			geoStatistic.setCreateTime(new Date());
			geoStatistic.setUpdateTime(new Date());
			geoStatistic.setCreateBy("admin");
			geoStatistic.setUpdateBy("user");
			geoStatistic.setDel(UDMDelEnums.UDMDel.DELETE.getValue());
			
			geoStatisticDao = session.getMapper(GeoStatisticDao.class);
			int i = geoStatisticDao.update(geoStatistic);
			System.out.println(i+"-----------------------------------");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	
	@Test
	public void DeviceStatistic_select_Test(){
		
		try {
			SqlSession session = MyBatisUtil.getSqlSession(true);
			UDMDeviceStatistic DeviceStatistic = new UDMDeviceStatistic();
			
			Map map = new HashedMap();

			map.put("adPutintoId", "0011");
			map.put("regionName", "HN");
			map.put("startTime", DateUtil.strToDateSql("2018-03-17 18:00:00"));
			map.put("endTime", DateUtil.strToDateSql("2018-03-19 18:00:00"));
			
			
			geoStatisticDao = session.getMapper(GeoStatisticDao.class);
			List<UDMDeviceStatistic>  DeviceStatistics= geoStatisticDao. getList(map);
			System.out.println(DeviceStatistics.size()+"-----------------------------------");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
